<template>
  <div>
    <el-button style="margin-bottom: 10px" @click="routerBack">返回</el-button>
    <div class="content">
      <div class="cardLeft">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="130px"
                label="现公司信息"
                style="background: #e1e1e1"
              />
              <el-form-item label="公司行政区划：" label-width="170px"
                ><span>{{ companyData.primevaadministrativedivision }}</span>
              </el-form-item>
              <el-form-item label="公司品牌名称：" label-width="170px"
                ><span>{{ companyData.primevabelongbrandname }}</span>
              </el-form-item>
              <el-form-item label="品牌公司名称：" label-width="170px"
                ><span>{{ companyData.primevacompanyname }}</span>
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
      <div class="cardRight">
        <el-card>
          <el-form :model="companyData" ref="companyData" label-width="140px">
            <el-card>
              <el-form-item
                label-width="170px"
                label="变更后公司信息"
                style="background: #e1e1e1"
              />
              <el-form-item label="公司行政区划：" label-width="170px" required>
                <el-col :span="6">
                  <el-form-item
                    prop="province"
                    :rules="[
                      { required: true, message: '请选择省', trigger: 'blur' },
                    ]"
                  >
                    <el-select
                      :disabled="active == 2"
                      v-model="companyData.province"
                      @change="selectProvince(companyData.province)"
                      placeholder="请选择省"
                    >
                      <el-option
                        v-for="item in provinces"
                        :key="item.areaid"
                        :label="item.areaname"
                        :value="item"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item
                    prop="city"
                    :rules="[
                      { required: true, message: '请选择市', trigger: 'blur' },
                    ]"
                  >
                    <el-select
                      :disabled="active == 2"
                      v-model="companyData.city"
                      @change="selectCity(companyData.city)"
                      placeholder="请选择市"
                    >
                      <el-option
                        v-for="item in citys"
                        :key="item.areaid"
                        :label="item.areaname"
                        :value="item"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item
                    prop="county"
                    :rules="[
                      { required: true, message: '请选择县', trigger: 'blur' },
                    ]"
                  >
                    <el-select
                      v-model="companyData.county"
                      @change="selectCounty"
                      :disabled="active == 2"
                      placeholder="请选择区/县"
                    >
                      <el-option
                        v-for="item in countys"
                        :key="item.areaid"
                        :label="item.areaname"
                        :value="item"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-form-item>
              <el-form-item
                label="公司品牌名称："
                label-width="170px"
                prop="newbelongbrandname"
                :rules="[
                  {
                    required: true,
                    message: '请输入公司品牌名称',
                    trigger: 'change',
                  },
                ]"
              >
                <el-input
                  :disabled="active == 2"
                  v-model="companyData.newbelongbrandname"
                  width="50%"
                  type="text"
                ></el-input>
              </el-form-item>
              <el-form-item label="品牌公司名称：" label-width="170px"
                ><span>{{ companyData.newcompanyname }}</span>
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
    </div>

    <div class="next">
      <div class="nextLeft">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="170px"
                label="品牌公司级别信息"
                style="background: #e1e1e1"
              />
              <div style="padding: 20px 0">
                <el-form-item label="品牌公司级别：" label-width="170px">
                  <span v-if="companyData.primevallevel == 1">全球公司</span>
                  <span v-else-if="companyData.primevallevel == 2"
                    >省级公司</span
                  >
                  <span v-else-if="companyData.primevallevel == 3"
                    >市级公司</span
                  >
                  <span v-else-if="companyData.primevallevel == 4"
                    >县级公司</span
                  >
                </el-form-item>
                <el-form-item label="品牌公司类型：" label-width="170px">
                  <span v-if="companyData.primevacompanytype == 0">孵化</span>
                  <span v-if="companyData.primevacompanytype == 1">临时</span>
                  <span v-if="companyData.primevacompanytype == 2">正式</span>
                </el-form-item>
              </div>
            </el-card>
          </el-form>
        </el-card>
      </div>
      <div class="nextRight">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="240px"
                label="变更后品牌公司级别信息"
                style="background: #e1e1e1"
              />

              <el-form-item label="品牌公司级别：" label-width="170px">
                <el-radio-group
                  :disabled="active == 2"
                  v-model="companyData.newlevel"
                >
                  <el-radio :label="1">全球公司</el-radio>
                  <el-radio :label="2">省级公司</el-radio>
                  <el-radio :label="3">市级公司</el-radio>
                  <el-radio :label="4">县级公司</el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item label="品牌公司类型：" label-width="170px">
                <el-radio-group
                  :disabled="active == 2"
                  v-model="companyData.newcompanytype"
                >
                  <el-radio :label="0">孵化</el-radio>
                  <el-radio :label="1">临时</el-radio>
                  <el-radio :label="2">正式</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
    </div>

    <div class="foot">
      <div class="footLeft">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="145px"
                label="开发关系信息"
                style="background: #e1e1e1"
              />
              <el-form-item label="上级品牌公司ID：" label-width="200px">
                <span>{{ companyData.primevadeveloprelationid }}</span>
              </el-form-item>
              <el-form-item label="上级品牌公司级别：" label-width="200px">
                <span
                  v-if="companyData.primevadeveloprelationlevel == 1"
                  style="color: #4acf1e"
                  >全球公司</span
                >
                <span
                  v-else-if="companyData.primevadeveloprelationlevel == 2"
                  style="color: #4acf1e"
                  >省级公司</span
                >
                <span
                  v-else-if="companyData.primevadeveloprelationlevel == 3"
                  style="color: #4acf1e"
                  >市级公司</span
                >
                <span
                  v-else-if="companyData.primevadeveloprelationlevel == 4"
                  style="color: #4acf1e"
                  >县级公司</span
                >
              </el-form-item>
              <el-form-item label="上级品牌公司类型：" label-width="200px">
                <span v-if="companyData.primevadeveloprelationtype == '0'"
                  >孵化公司</span
                >
                <span v-else-if="companyData.primevadeveloprelationtype == '1'"
                  >临时公司</span
                >
                <span v-else-if="companyData.primevadeveloprelationtype == '2'"
                  >正式公司</span
                >
              </el-form-item>
              <el-form-item label="上级品牌公司名称：" label-width="200px">
                <span>{{ companyData.primevadeveloprelationname }}</span>
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
      <div class="footRight">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="220px"
                label="变更后开发关系信息"
                style="background: #e1e1e1"
              />

              <el-form-item label="上级品牌公司ID：" label-width="200px">
                <span>{{ companyData.newdeveloprelationid }}</span>
                <el-button
                  v-show="active == 1"
                  type="primary"
                  size="small"
                  icon="el-icon-edit"
                  style="margin-left: 50%"
                  @click="serchCompany"
                  >品牌公司查询
                </el-button>
              </el-form-item>
              <el-form-item label="上级品牌公司级别 :" label-width="200px">
                <span
                  v-if="companyData.newdeveloprelationlevel == 1"
                  style="color: #4acf1e"
                  >全球公司</span
                >
                <span
                  v-else-if="companyData.newdeveloprelationlevel == 2"
                  style="color: #4acf1e"
                  >省级公司</span
                >
                <span
                  v-else-if="companyData.newdeveloprelationlevel == 3"
                  style="color: #4acf1e"
                  >市级公司</span
                >
                <span
                  v-else-if="companyData.newdeveloprelationlevel == 4"
                  style="color: #4acf1e"
                  >县级公司</span
                >
              </el-form-item>
              <el-form-item label="上级品牌公司类型：" label-width="200px">
                <span v-if="companyData.newdeveloprelationtype == '0'"
                  >孵化公司</span
                >
                <span v-else-if="companyData.newdeveloprelationtype == '1'"
                  >临时公司</span
                >
                <span v-else-if="companyData.newdeveloprelationtype == '2'"
                  >正式公司</span
                >
              </el-form-item>
              <el-form-item label="上级品牌公司名称：" label-width="200px">
                {{ companyData.newdeveloprelationname }}
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
    </div>

    <div class="end">
      <div class="endLeft">
        <el-card>
          <el-form label-width="140px">
            <el-card>
              <el-form-item
                label-width="55%"
                label="品牌公司组织结构设置"
                style="background: #e1e1e1"
              />
              <el-form-item label="创始人信息：" label-width="170px">
                <el-table
                  border
                  :data="companyoriginator"
                  v-loading="loading"
                  :header-cell-style="getRowClass"
                >
                  <el-table-column
                    label="商城ID"
                    align="center"
                    prop="companyoriginatorid"
                  >
                  </el-table-column>
                  <el-table-column
                    label="商城公司账号"
                    align="center"
                    prop="originatoraccount"
                  >
                  </el-table-column>
                  <el-table-column
                    label="商城公司名称"
                    align="center"
                    prop="originatorcompanyname"
                  >
                  </el-table-column>
                </el-table>
              </el-form-item>
              <el-form-item
                style="margin-top: 20px"
                label="首席合伙人信息："
                label-width="170px"
              >
                <div class="oneInfo">
                  <div class="oneLeft">
                    <span>【原首席合伙人】</span>
                    <el-table
                      border
                      :data="primevaceo"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="primevaceoid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="primevaceotype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.primevaceotype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.primevaceotype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.primevaceotype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="primevaceoaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="primevaceocompanyname"
                      >
                      </el-table-column>
                    </el-table>
                  </div>
                  <div class="oneRight">
                    <span
                      >【变更后首席合伙人】<el-button
                        v-show="active == 1"
                        type="warning"
                        size="small"
                        icon="el-icon-edit"
                        style="float: right"
                        @click="firstPartnerDialogShow"
                        >首席合伙人变更</el-button
                      ></span
                    >
                    <el-table
                      border
                      :data="changePrimevaceo"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="primevaceoid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="primevaceotype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.primevaceotype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.primevaceotype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.primevaceotype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="primevaceoaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="primevaceocompanyname"
                      >
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </el-form-item>
              <el-form-item
                style="margin-top: 20px"
                label="高级合伙人信息："
                label-width="170px"
              >
                <div class="oneInfo">
                  <div class="oneLeft">
                    <span
                      >【新增】<el-button
                        v-show="active == 1"
                        type="primary"
                        size="small"
                        icon="el-icon-edit"
                        style="float: right"
                        @click="addPartnerDialogShow(1)"
                        >添加高级合伙人</el-button
                      ></span
                    >
                    <el-table
                      border
                      :data="companyData.addSeniorPartners"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                      height="300px"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="entityid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="partnertype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.partnertype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="entityaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="entitycompanyname"
                      >
                        <template slot-scope="scope">
                          <span style="color: #4acf1e">{{
                            scope.row.entitycompanyname
                          }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                          <el-button
                            type="danger"
                            size="mini"
                            @click="deleteHighPartner(scope.row)"
                            >删除</el-button
                          >
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                  <div class="oneRight">
                    <span
                      >【删除】<el-button
                        v-show="active == 1"
                        type="danger"
                        size="small"
                        icon="el-icon-edit"
                        style="float: right"
                        @click="addPartnerDialogShow(3)"
                        >删除高级合伙人</el-button
                      ></span
                    >
                    <el-table
                      border
                      :data="companyData.delSeniorPartners"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                      height="300px"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="entityid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="partnertype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.partnertype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="entityaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="entitycompanyname"
                      >
                        <template slot-scope="scope">
                          <span style="color: #4acf1e">{{
                            scope.row.entitycompanyname
                          }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </el-form-item>

              <el-form-item
                style="margin-top: 20px"
                label="合伙人信息："
                label-width="170px"
              >
                <div class="oneInfo">
                  <div class="oneLeft">
                    <span
                      >【新增】<el-button
                        v-show="active == 1"
                        type="primary"
                        size="small"
                        icon="el-icon-edit"
                        style="float: right"
                        @click="addPartnerDialogShow(2)"
                        >添加合伙人</el-button
                      ></span
                    >
                    <el-table
                      border
                      :data="companyData.addPartners"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                      height="300px"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="entityid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="partnertype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.partnertype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="entityaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="entitycompanyname"
                      >
                        <template slot-scope="scope">
                          <span style="color: #4acf1e">{{
                            scope.row.entitycompanyname
                          }}</span>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作" align="center">
                        <template slot-scope="scope">
                          <el-button
                            type="danger"
                            size="mini"
                            @click="deletePartner(scope.row)"
                            >删除</el-button
                          >
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                  <div class="oneRight">
                    <span
                      >【删除】<el-button
                        v-show="active == 1"
                        type="danger"
                        size="small"
                        icon="el-icon-edit"
                        style="float: right"
                        @click="addPartnerDialogShow(4)"
                        >删除合伙人</el-button
                      ></span
                    >
                    <el-table
                      border
                      :data="companyData.delPartners"
                      v-loading="loading"
                      :header-cell-style="getRowClass"
                      height="300px"
                    >
                      <el-table-column
                        label="商城ID"
                        align="center"
                        prop="entityid"
                      >
                      </el-table-column>
                      <el-table-column
                        label="合伙人类型"
                        align="center"
                        prop="partnertype"
                      >
                        <template slot-scope="scope">
                          <span
                            v-if="scope.row.partnertype == 0"
                            style="color: #4acf1e"
                            >孵化</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 1"
                            style="color: #4acf1e"
                            >临时</span
                          >
                          <span
                            v-else-if="scope.row.partnertype == 2"
                            style="color: #4acf1e"
                            >正式</span
                          >
                        </template>
                      </el-table-column>
                      <el-table-column
                        label="商城公司账号"
                        align="center"
                        prop="entityaccount"
                      >
                      </el-table-column>
                      <el-table-column
                        label="商城公司名称"
                        align="center"
                        prop="entitycompanyname"
                      >
                        <template slot-scope="scope">
                          <span style="color: #4acf1e">{{
                            scope.row.entitycompanyname
                          }}</span>
                        </template>
                      </el-table-column>
                    </el-table>
                  </div>
                </div>
              </el-form-item>
              <el-form-item>
                <span>
                  <el-button
                    v-show="active == 1"
                    type="primary"
                    style="margin-left: 35%"
                    @click="onrest"
                    >组织结构恢复</el-button
                  >
                  <el-button
                    v-show="active == 1"
                    @click="changeIt"
                    type="success"
                    >公司组织结构变更</el-button
                  >
                  <el-button
                    type="warning"
                    style="margin-left: 35%"
                    v-show="active == 2"
                    @click="cancel"
                    >取消</el-button
                  >
                  <el-button
                    v-show="active == 2"
                    :loading="editFlag"
                    @click="quitChange"
                    type="success"
                    >确认变更</el-button
                  >
                </span>
              </el-form-item>
            </el-card>
          </el-form>
        </el-card>
      </div>
    </div>
    <el-dialog
      :title="partnerDialogTitle"
      :visible.sync="partnerDialog"
      width="40%"
      min-width="500px"
      class="partner-dialog"
      :close-on-click-modal="false"
      :before-close="partnerDialogClose"
    >
      <el-table
        ref="partnerTable"
        :data="partnerTableData"
        v-loading="partnerLoading"
        style="width: 100%"
        tooltip-effect="dark"
        @selection-change="partnerSelectChange"
        @select-all="partnerSelectChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="userId" align="center" label="商城ID">
        </el-table-column>
        <el-table-column
          prop="relationType"
          align="center"
          label="合伙人类型"
          width="100px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.relationType == 0" style="color: #4acf1e"
              >孵化</span
            >
            <span v-else-if="scope.row.relationType == 1" style="color: #4acf1e"
              >临时</span
            >
            <span v-else-if="scope.row.relationType == 2" style="color: #4acf1e"
              >正式</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="userMobile" align="center" label="商城公司账号">
        </el-table-column>
        <el-table-column
          prop="enterpriseName"
          align="center"
          label="商城公司名称"
        >
          <template slot-scope="scope">
            <span style="color: #4acf1e">{{ scope.row.enterpriseName }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px; display: flex; justify-content: center">
        <el-pagination
          class="pagination-container"
          background
          :page-size="partnerQuery.page.pageSize"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total,sizes,prev, pager, next, jumper"
          :current-page="partnerQuery.page.currentPage"
          :page-sizes="[5, 10, 20, 30, 50]"
          :total="totalNumber"
        ></el-pagination>
      </div>

      <el-row type="flex" class="btns">
        <el-button type="primary" @click="partnerConfirm">确定</el-button>
        <el-button type="danger" @click="partnerCancel">取消</el-button>
      </el-row>
    </el-dialog>
    <el-dialog
      title="可变更首席合伙人列表"
      :visible.sync="firstPartnerDialog"
      width="40%"
      min-width="500px"
      :close-on-click-modal="false"
      class="partner-dialog"
      :before-close="firstPartnerDialogClose"
    >
      <el-table
        ref="partnerTable"
        :data="firstPartnerTableData"
        v-loading="loading"
        style="width: 100%"
        tooltip-effect="dark"
        @current-change="firstPartnerSelectChange"
      >
        <el-table-column label="选择" width="55">
          <template slot-scope="scope">
            <el-radio v-model="firstPartnerSelect" :label="scope.row"
              ><i></i
            ></el-radio>
          </template>
        </el-table-column>
        <el-table-column prop="userId" align="center" label="商城ID">
        </el-table-column>
        <el-table-column prop="relationType" align="center" label="合伙人类型">
          <template slot-scope="scope">
            <span v-if="scope.row.relationType == 0" style="color: #4acf1e"
              >孵化</span
            >
            <span v-else-if="scope.row.relationType == 1" style="color: #4acf1e"
              >临时</span
            >
            <span v-else-if="scope.row.relationType == 2" style="color: #4acf1e"
              >正式</span
            >
          </template>
        </el-table-column>
        <el-table-column prop="userMobile" align="center" label="商城公司账号">
        </el-table-column>
        <el-table-column prop="name" align="center" label="商城公司名称">
          <template slot-scope="scope">
            <span style="color: #4acf1e">{{ scope.row.enterpriseName }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin: 20px 0 20px 20px">
        <span>首席合伙人类型:</span>
        <el-radio-group v-model="firstPartnerType">
          <el-radio :label="0">孵化</el-radio>
          <el-radio :label="2">正式</el-radio>
        </el-radio-group>
      </div>
      <el-row type="flex" class="btns">
        <el-button type="primary" @click="firstPartnerConfirm">确定</el-button>
        <el-button type="danger" @click="firstPartnerCancel">取消</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { getAreaList } from "../../api/companyRelation";
import {
  getPartnerList,
  getWorkDetail,
  getFristList,
  addOrEditCompanyData,
} from "../../api/handWork/handWorkList";
export default {
  data() {
    return {
      active: 1, //控制显示刷新还是确认提交
      //品牌公司属性
      company: {
        radio: "",
        type: "",
      },
      //省市县区域名称
      companyData: {},
      // cloneCompanyData: {}, //克隆数据
      // companyData: {},
      provinces: [],
      citys: [],
      countys: [],
      data: [],
      companyid: null, //上个页面传递的公司id
      loading: false,
      partnerDialogTitle: "添加合伙人", //合伙人对话框标题
      partnerDialog: false, //合伙人对话框
      partnerTableData: [], //合伙人表格数据
      partnerSelect: [], //当前选中的合伙人
      partnerType: null, //合伙人类型
      totalNumber: 0, //数据条数
      partnerLoading: false,
      // 合伙人请求参数
      partnerQuery: {
        companyId: 0,
        flag: 0,
        page: {
          currentPage: 1,
          pageSize: 5,
        },
      },
      baseInfo: {
        province: "",
        city: "",
        county: "",
      },
      firstPartnerDialog: false, //首席合伙人对话框
      firstPartnerTableData: [], //首席合伙人表格数据
      firstPartnerSelect: [], //当前选中的首席合伙人
      firstPartnerType: 2, //首席合伙人类型
      radioType: null, //单选合伙人类型
      companyoriginator: [], //创始人数组
      primevaceo: [], //首席数组
      changePrimevaceo: [], //变更首席合伙人数组
      flag: true,
      editFlag: false,
    };
  },
  async created() {
    if (this.$route.query.companyid) {
      this.companyid = this.$route.query.companyid;

      this.getCompanyDateil();
    } else if (this.$route.params.company) {
    }
  },
  async activated() {
    if (this.flag) return;
    console.log("缓存");
    this.active = 1;
    if (this.$route.query.companyid) {
      this.companyid = this.$route.query.companyid;
      await this.getCompanyDateil();
    } else if (this.$route.params.company) {
      const {
        performanceLevel,
        companyId,
        companyName,
        companyType,
      } = this.$route.params.company;
      this.companyData.newdeveloprelationid = companyId;
      this.companyData.newdeveloprelationlevel = performanceLevel;
      this.companyData.newdeveloprelationtype = companyType;
      this.companyData.newdeveloprelationname = companyName;
    }
  },
  async mounted() {},
  computed: {},
  watch: {},
  methods: {
    getCompanyDateil() {
      getWorkDetail({ companyid: this.companyid })
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.companyData = res.data;

          // 新信息赋值

          this.companyData.newadministrativedivision =
            res.data.primevaadministrativedivision;
          this.companyData.newbelongbrandname = res.data.primevabelongbrandname;
          if (res.data.primevabelongbrandname) {
            this.companyData.newcompanyname = res.data.primevacompanyname;
          }
          this.companyData.newlevel = res.data.primevallevel;
          this.companyData.newcompanytype = res.data.primevacompanytype;
          this.companyData.newdeveloprelationid =
            res.data.primevadeveloprelationid;
          this.companyData.newdeveloprelationlevel =
            res.data.primevadeveloprelationlevel;
          this.companyData.newdeveloprelationtype =
            res.data.primevadeveloprelationtype;
          this.companyData.newdeveloprelationname =
            res.data.primevadeveloprelationname;
          this.companyData.newceotype = res.data.primevaceocotype;
          this.companyData.newceoaccount = res.data.primevaceoaccount;
          this.companyData.newceocompanyname = res.data.primevaceocompanyname;
          this.companyData.newceoid = res.data.primevaceoid;

          // 绑定地址
          const baseInfo = this.companyData.primevaadministrativedivision.split(
            ","
          );
          this.companyData.province = baseInfo[0];
          this.companyData.city = baseInfo[1];
          this.companyData.county = baseInfo[2];

          console.log("公司详情", this.companyData);
          // 绑定创始人表格
          this.companyoriginator = [
            {
              companyoriginatorid: res.data.companyoriginatorid,
              originatoraccount: res.data.originatoraccount,
              originatorcompanyname: res.data.originatorcompanyname,
            },
          ];
          if (
            res.data.primevaceotype ||
            res.data.primevaceoid ||
            res.data.primevaceoaccount ||
            res.data.primevaceocompanyname
          ) {
            // 绑定首席表格
            this.primevaceo = [
              {
                primevaceotype: res.data.primevaceotype,
                primevaceoid: res.data.primevaceoid,
                primevaceoaccount: res.data.primevaceoaccount,
                primevaceocompanyname: res.data.primevaceocompanyname,
              },
            ];
            this.changePrimevaceo = [
              {
                primevaceotype: res.data.primevaceotype,
                primevaceoid: res.data.primevaceoid,
                primevaceoaccount: res.data.primevaceoaccount,
                primevaceocompanyname: res.data.primevaceocompanyname,
              },
            ];
          } else {
            this.primevaceo = [];
            this.changePrimevaceo = [];
          }
          this.getAddressMap();
          this.flag = false;
        })
        .catch(() => {
          this.flag = false;
          this.$message.error("数据获取失败,请重新选择");
          this.companyData = {};
        });
    },
    //获取全国省市县
    areaList(provinceid, cityRank) {
      // debugger
      const data = [];
      getAreaList({ provinceid: provinceid })
        .then((response) => {
          // console.log(response)
          if (response.code != 0) {
            this.$message.error(response.message);
            return false;
          }
          switch (cityRank) {
            case 0: // 省列表
              this.provinces = response.data || []; // 省级列表赋值
              break;
            case 1: // 市列表
              this.companyData.city = null; // 清除已选市
              this.companyData.county = null; // 清除已选县
              this.citys = []; // 清空市类别
              this.countys = []; // 清空县列表
              this.citys = response.data || []; // 市级列表赋值
              break;
            case 2: // 县列表
              this.companyData.county = null; // 清除已选县
              this.countys = []; // 清空县列表
              this.countys = response.data || []; // 县级列表赋值
              break;
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    // 选择省
    selectProvince(item) {
      this.areaList(item.areaid, 1);
      this.companyData.province = this.companyData.province.areaname;
    },
    // 选择市
    selectCity(item) {
      this.areaList(item.areaid, 2);
      this.companyData.city = this.companyData.city.areaname;
    },
    // 选择县
    selectCounty(item) {
      this.companyData.county = item.areaname;
      this.$forceUpdate();
    },
    getAddressMap() {
      getAreaList({ provinceid: null })
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.provinces = res.data || []; // 省级列表赋值
          const province = this.provinces.filter((v) => {
            return v.areaname == this.companyData.province;
          });
          getAreaList({ provinceid: province[0].areaid })
            .then((res) => {
              if (res.code != 0) {
                this.$message.error(res.message);
                return false;
              }
              this.citys = res.data || []; // 市级列表赋值
              let city = "";
              this.citys.some((v) => {
                if (v.areaname == this.companyData.city) {
                  city = v.areaid;
                  return true;
                }
              });
              getAreaList({ provinceid: city })
                .then((res) => {
                  if (res.code != 0) {
                    this.$message.error(res.message);
                    return false;
                  }
                  this.countys = res.data || []; // 县级列表赋值
                })
                .catch((err) => {
                  this.$message.error(err);
                });
            })
            .catch((err) => {
              this.$message.error(err);
            });
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
    //品牌公司查询
    serchCompany() {
      this.$router.push({
        name: "品牌公司查询列表",
        params: {
          newlevel: this.companyData.newlevel,
          companyId: this.companyid,
        },
      });
    },
    //获取表头的颜色
    getRowClass({ rowIndex }) {
      if (rowIndex == 0) {
        return "background:RGB(238,239,246)";
      } else {
        return "";
      }
    },
    //组织架构恢复
    onrest() {
      this.getCompanyDateil();
    },
    //公司组织结构变更
    changeIt() {
      console.log("开发", this.companyData.newdeveloprelationlevel);
      console.log("现公司", this.companyData.newlevel);
      if (
        this.companyData.newlevel - this.companyData.newdeveloprelationlevel !==
        1
      ) {
        return this.$message.error(
          "开发关系和公司关系不匹配,请重新选择(开发关系比公司关系高一级)"
        );
      }
      this.$refs.companyData.validate((valid) => {
        if (valid) {
          this.active = 2;
          this.$message.warning("请检查变更信息");
          const data = this.companyData;
          const baseInfo = this.companyData.newadministrativedivision.split(
            ","
          );
          if (data.newlevel == 1) {
            this.companyData.newcompanyname = `${baseInfo[0]}金天合纵${data.newbelongbrandname}企业管理咨询公司`;
          } else if (data.newlevel == 2) {
            this.companyData.newcompanyname = `${baseInfo[0]}金天合纵${data.newbelongbrandname}企业管理咨询公司`;
          } else if (data.newlevel == 3) {
            this.companyData.newcompanyname = `${
              baseInfo[0] + baseInfo[1]
            }金天合纵${data.newbelongbrandname}企业管理咨询公司`;
          } else if (data.newlevel == 4) {
            this.companyData.newcompanyname = `${
              baseInfo[0] + baseInfo[1] + baseInfo[2]
            }金天合纵${data.newbelongbrandname}企业管理咨询公司`;
          } else {
            this.companyData.newcompanyname = "";
          }
        } else {
          this.$message.error("请检查必填信息");
        }
      });
    },
    // 确认变更
    quitChange() {
      this.editFlag = true;
      this.companyData.changetype = 1;
      this.companyData.newadministrativedivision = `${this.companyData.province},${this.companyData.city},${this.companyData.county}`;
      addOrEditCompanyData(this.companyData)
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            this.editFlag = false;
            return false;
          }
          this.editFlag = false;
          console.log(res, "编辑公司");
          this.$message.success("修改成功");
          this.active = 1;
          this.$router.push({ name: "公司关系设置" });
        })
        .catch((err) => {
          this.editFlag = false;
        });
    },
    cancel() {
      this.active = 1;
    },
    //   合伙人对话框显示
    async addPartnerDialogShow(partnerType) {
      this.partnerType = partnerType;

      if (partnerType == 1) {
        console.log(partnerType, "状态");
        this.partnerDialogTitle = "可添加高级合伙人列表";
      } else if (partnerType == 2) {
        this.partnerDialogTitle = "可添加合伙人列表";
      } else if (partnerType == 3) {
        this.partnerDialogTitle = "可删除高级合伙人列表";
      } else if (partnerType == 4) {
        this.partnerDialogTitle = "可删除合伙人列表";
      }
      await this.getPartnerLists();
      this.partnerDialog = true;
    },
    //获取合伙人列表
    getPartnerLists() {
      this.partnerLoading = true;
      this.partnerQuery.companyId = this.companyid;
      this.partnerQuery.flag = this.partnerType;
      getPartnerList(this.partnerQuery)
        .then((res) => {
          this.partnerLoading = false;
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.partnerTableData = res.data.list;
          this.totalNumber = res.data.totalNumber;
        })
        .catch(() => {
          this.partnerTableData = [];
          this.partnerLoading = false;
        });
    },
    //获取首席合伙人列表
    getFristLists() {
      getFristList({ companyId: this.companyid })
        .then((res) => {
          if (res.code != 0) {
            this.$message.error(res.message);
            return false;
          }
          this.firstPartnerTableData = res.data;
        })
        .catch(() => {
          this.firstPartnerTableData = [];
        });
    },
    //  合伙人选中改变
    partnerSelectChange(val) {
      console.log(val);
      this.partnerSelect = val;
    },
    // 首席合伙人选择改变事件
    firstPartnerSelectChange(val) {
      this.firstPartnerSelect = val;
    },
    // 合伙人对话框关闭
    partnerDialogClose(done) {
      this.clearPartnerData();
      done();
    },
    firstPartnerDialogClose(done) {
      this.clearFirstPartnerData();
      done();
    },
    // 清空首席合伙人数据
    clearFirstPartnerData() {
      this.firstPartnerSelect = [];
      this.firstPartnerTableData = [];
    },
    // 清空合伙人数据
    clearPartnerData() {
      this.partnerSelect = [];
      this.partnerTableData = [];
    },
    //   合伙人确定
    partnerConfirm() {
      const type = this.partnerType;
      this.partnerSelect.forEach((v) => {
        v.entityid = v.userId;
        v.partnertype = v.relationType;
        v.entityaccount = v.userMobile;
        v.entitycompanyname = v.enterpriseName;
        v.companyMemberRelation = {
          relationid: v.relationId,
        };

        if (type == 1 || type == 3) {
          v.partnerlevel = 1;
          v.changetype = 0;
          v.partnertype = 2;
        } else if (type == 2 || type == 4) {
          v.partnerlevel = 0;
          v.changetype = 1;
        }
      });
      if (type == 1) {
        this.partnerSelect.forEach((v) => {
          const index = this.companyData.addSeniorPartners.findIndex(
            (i) => i.entityid == v.entityid
          );
          if (index == -1) {
            this.companyData.addSeniorPartners.push(v);
          }
        });
      } else if (type == 2) {
        this.partnerSelect.forEach((v) => {
          const index = this.companyData.addPartners.findIndex(
            (i) => i.entityid == v.entityid
          );
          if (index == -1) {
            this.companyData.addPartners.push(v);
          }
        });
      } else if (type == 3) {
        this.partnerSelect.forEach((v) => {
          const index = this.companyData.delSeniorPartners.findIndex(
            (i) => i.entityid == v.entityid
          );
          if (index == -1) {
            this.companyData.delSeniorPartners.push(v);
          }
        });
      } else if (type == 4) {
        this.partnerSelect.forEach((v) => {
          const index = this.companyData.delPartners.findIndex(
            (i) => i.entityid == v.entityid
          );
          if (index == -1) {
            this.companyData.delPartners.push(v);
          }
        });
      }

      this.partnerDialog = false;
      this.clearPartnerData();
    },
    //   合伙人取消
    partnerCancel() {
      this.$message.info("已取消");
      this.partnerDialog = false;
      this.clearPartnerData();
    },
    // 首席合伙人对话框显示
    firstPartnerDialogShow() {
      this.getFristLists();
      this.firstPartnerDialog = true;
    },
    // 首席合伙人确定
    firstPartnerConfirm() {
      if (this.firstPartnerSelect.userId) {
        const data = this.firstPartnerSelect;
        this.changePrimevaceo = [
          {
            primevaceotype: this.firstPartnerType,
            primevaceoid: data.userId,
            primevaceoaccount: data.userMobile,
            primevaceocompanyname: data.enterpriseName,
          },
        ];
        this.companyData.newceotype = this.firstPartnerType;
        this.companyData.newceoaccount = data.userMobile;
        this.companyData.newceocompanyname = data.enterpriseName;
        this.companyData.newceoid = data.userId;
      }

      this.firstPartnerDialog = false;
      this.clearFirstPartnerData();
    },
    // 首席合伙人取消
    firstPartnerCancel() {
      this.$message.info("已取消");
      this.firstPartnerDialog = false;
      this.clearFirstPartnerData();
    },
    // 删除高级合伙人
    async deleteHighPartner(row) {
      try {
        await this.$confirm("是否确认删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        });
        const index = this.companyData.addSeniorPartners.findIndex(
          (v) => v.entityid == row.entityid
        );
        if (index !== -1) {
          this.companyData.addSeniorPartners.splice(index, 1);
        }
        this.$message.success("删除成功");
      } catch {
        this.$message.info("已取消");
      }
    },
    //  删除合伙人
    async deletePartner(row) {
      try {
        await this.$confirm("是否确认删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        });
        const index = this.companyData.addPartners.findIndex(
          (v) => v.entityid == row.entityid
        );
        if (index !== -1) {
          this.companyData.addPartners.splice(index, 1);
        }
        this.$message.success("删除成功");
      } catch {
        this.$message.info("已取消");
      }
    },
    handleSizeChange(val) {
      this.partnerQuery.page.pageSize = val;
      this.getPartnerLists();
    },
    handleCurrentChange(val) {
      this.partnerQuery.page.currentPage = val;
      this.getPartnerLists();
    },
    //确认变更
    submit() {},
    //取消
    routerBack() {
      this.$router.push({
        name: "公司关系设置",
      });
    },
    back() {
      this.active = 1;
    },
  },
};
</script>
<style scoped lang="scss">
.el-form-item /deep/ .el-form-item__label {
  font-size: 16px;
}
.content {
  display: flex;
}
.cardLeft {
  width: 45%;
}
.cardRight {
  margin-left: 10%;
  width: 45%;
}

.next {
  margin: 60px auto;
  display: flex;
}
.nextLeft {
  width: 45%;
}
.nextRight {
  margin-left: 10%;
  width: 45%;
}

.foot {
  margin: 60px auto;
  display: flex;
}
.footLeft {
  width: 45%;
}
.footRight {
  margin-left: 10%;
  width: 45%;
}

.end {
  margin: 60px auto;
  display: flex;
}
.endLeft {
  width: 100%;
}

.oneInfo {
  display: flex;
}
.oneLeft {
  width: 40%;
}
.oneRight {
  margin-left: 10%;
  width: 40%;
}
/deep/ .partner-dialog {
  .btns {
    margin-top: 50px;
    justify-content: space-between;
    padding: 0 150px;
  }
}
</style>
